package com.controller;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.pojo.Base;


@Controller
public class BaseController {
	
	private static final Logger logger = LoggerFactory.getLogger(BaseController.class);

	@GetMapping(value="/index")
	public String index(Map<String, Object> map,Model model) {
		map.put("key", "this is a value ...");
		Timestamp ts = new Timestamp(new Date().getTime());
		map.put("time", ts);
		logger.info("index is running..."+ts.toString());
		model.addAttribute("title","this is a title ...");
		model.addAttribute("operateTime",new Timestamp(new Date().getTime()));
		return "base/index";
	}
	
	@PostMapping("/index2")
	@ResponseBody
	public String index2(Map<String, Object> map) {
		
		map.put("key","this is a value ...");
		Timestamp ts = new Timestamp(new Date().getTime());
		map.put("time",ts);
		JSONObject jpo = new JSONObject(map);
		String str = jpo.toJSONString();
		return str;
	}
	
	@GetMapping("/error")
	public String error() {
		return "error";
	}
	
}
